<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>点击发送跨域请求</button>
    <div id="result">

    </div>
    <script>
        // 1. 获取按钮和result
        let btn = document.querySelector('button')
        let result = document.querySelector('#result')
        // 2. 定义一个命名函数，设置形参
        function fn(res){
            // 2.1 将参数数据放入到result标签内
            result.innerHTML = res.name;
        }
            
        // 3. 绑定点击事件
        btn.onclick = function(){
             // 3.1 创建script标签
             let script = document.createElement('script');
            // 3.2 输入script的src路径
            script.src = 'http://localhost/jsonpdemo';
            // 3.3 将script插入到body中
            document.body.appendChild(script);
        }
           
    </script>
</body>

</html>